package ylsb.service;


import org.springframework.stereotype.Service;
import ylsb.dao.HaocaiyinjinMapper;
import ylsb.dao.YiyonghaocaiMapper;
import ylsb.model.Haocaiyinjin;
import ylsb.model.HaocaiyinjinExample;
import ylsb.model.Yiyonghaocai;
import ylsb.model.YiyonghaocaiExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class YiyonghaocaiService {

    @Resource
    YiyonghaocaiMapper ddMapper;

    public boolean isexistByxiangmuId(String xiangmuId){
        YiyonghaocaiExample mmExample=new YiyonghaocaiExample();
        YiyonghaocaiExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.selectByExample(mmExample).size()>0;
    }

    public boolean add (Yiyonghaocai ddYiyonghaocai){
        return ddMapper.insert(ddYiyonghaocai)==1;
    }

    public List<Map<String, Object>> findPinzhongAll(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinzhongAll(ppxiangmuId,mmStartIndex,ppPageSize);
    }

    public List<Map<String, Object>> findPinpaiByPinzhong(String ppxiangmuId,String mmPinzhongOne){
        return ddMapper.findPinpaiByPinzhong(ppxiangmuId,mmPinzhongOne);
    }
    public List<Map<String, Object>> findPinpaiFenlei(String ppxiangmuId,String mmPinzhongOne){
        return ddMapper.findPinpaiFenlei(ppxiangmuId,mmPinzhongOne);
    }

    public List<Map<String, Object>> findXinghaoByPinpai(String ppxiangmuId,String ppPinzhong,String ppPinpai){
        return ddMapper.findXinghaoByPinpai(ppxiangmuId,ppPinzhong,ppPinpai);
    }
    public List<Map<String, Object>> findPinpaiResultByPinzhong(String ppxiangmuId,String ppuserId,String mmPinzhongOne){
        return ddMapper.findPinpaiResultByPinzhong(ppxiangmuId,ppuserId,mmPinzhongOne);
    }
    public Integer getYiyonghaocailist(String ppxiangmuId,int ppPageIndex, int ppPageSize) {
        Object mmCount = ddMapper.getYiyonghaocailist(ppxiangmuId,ppPageIndex,ppPageSize);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }
    public boolean deleteByxiangmuId(String xiangmuId){
        YiyonghaocaiExample mmExample=new YiyonghaocaiExample();
        YiyonghaocaiExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.deleteByExample(mmExample)>=0;
    }
    public Yiyonghaocai findOne(String id){
        return ddMapper.selectByPrimaryKey(id);
    }
    public Integer getVoteCount(String ppxiangmuId){
        List<Map<String, Object>> list=ddMapper.findPinzhongAndPinpaiByXiangmuId(ppxiangmuId);
        return list == null ? 0 : list.size();
    }
    public List<Map<String, Object>> findDaochuPinzhongAll(String ppxiangmuId){
        return ddMapper.findDaochuPinzhongAll(ppxiangmuId);
    }
    public List<Map<String, Object>> findResultGuochanBypinzhong(String ppxiangmuId, String ppuserId,String ppPinzhong){
        return ddMapper.findResultGuochanBypinzhong(ppxiangmuId,ppuserId,ppPinzhong);
    }
    public List<Map<String, Object>> findZuanjiBypinzhong(String ppxiangmuId,String ppPinzhong,String ppPinpai){
        return ddMapper.findZuanjiBypinzhong(ppxiangmuId,ppPinzhong,ppPinpai);
    }
    public List<Map<String, Object>> findGuochanBypinzhong(String ppxiangmuId,String ppPinzhong){
        return ddMapper.findGuochanBypinzhong(ppxiangmuId,ppPinzhong);
    }
    public List<Map<String, Object>> findGuochanBypinzhongAndpinpai(String ppxiangmuId,String ppPinzhong,String ppPinpai){
        return ddMapper.findGuochanBypinzhongAndpinpai(ppxiangmuId,ppPinzhong,ppPinpai);
    }
    public List<Map<String, Object>> findyibaoBypinzhongAndpinpai(String ppxiangmuId,String ppPinzhong,String ppPinpai){
        return ddMapper.findyibaoBypinzhongAndpinpai(ppxiangmuId,ppPinzhong,ppPinpai);
    }
    public List<Map<String, Object>> findXinghaoJieguoByPinpai(String ppPinzhong,String ppPinpai,String ppxiangmuId, String ppuserId){
        return ddMapper.findXinghaoJieguoByPinpai(ppPinzhong,ppPinpai,ppxiangmuId,ppuserId);
    }



}
